define(function (require, exports, module) {
    var $ = require("jquery");
    require("pagination");
    var util = require("util");
    var ui = require("ui");
    var angular = require("angular");

    var raiseFinanceBaseModule = angular.module('raiseFinanceBaseModule', []);

    function baseDataService($http, $q, $location) {
        var service = {
            // 基础数据是否加载
            loaded: false,
            // 项目列表
            projectList: [],
            // 选择的项目 ID
            projectId: '',

        // 楼盘列表发生了变化
        projectChanged: function () {
            if (!service.projectId) {
                return;
            }

            /*service.getCustomerMode().then(function() {
             if (service.khmode == 1 && $location.path().substr(0, 2) == '/1') {
             // 推荐模式时，如果当前路由为带看则跳转到认筹标签
             $location.path('/5/1');
             }

             service.query();
             });*/
        }
    ,

        // 初始化查询表单数据
        initData: function () {
            var promises = [
                // 楼盘列表
                $http.get('/api/index.php?r=qmyx/customer-manage/get-buildings-by-project-ids')
            ];

            return $q.all(promises).then(function (xhrs) {
                var i = 0;
                service.projectList = xhrs[i++].data.data;

                service.projectId = service.projectList && service.projectList[0] && service.projectList[0].p_projectId
                || service.projectId;
                if (!service.projectId) {
                    return;
                }
                service.loaded = true;
            });
        }

    };

    return service;
}

raiseFinanceBaseModule.factory('raiseFinanceBaseData', ['$http', '$q', '$location', baseDataService]);


module.exports = raiseFinanceBaseModule;
})
;